package com.medishare.fragment;

import com.medishare.R;
import com.medishare.activity.ActivityBookDoctor;
import com.medishare.activity.ActivityCallAssistant;
import com.medishare.activity.ActivityCommunityActivity;
import com.medishare.activity.ActivityDoctorNotice;
import com.medishare.activity.ActivityFollowUpRecord;
import com.medishare.activity.ActivityHealthClass;
import com.medishare.activity.ActivityHealthKnowl;
import com.medishare.activity.ActivityHealthTest;
import com.medishare.activity.ActivityHealthTip;
import com.medishare.activity.ActivityMediReminder;
import com.medishare.activity.ActivityVaccineNotice;
import com.medishare.activity.ActivityWeatherNotice;
import com.medishare.activity.MainActivity;
import com.medishare.adapter.SpeeddialAdapter;

import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.GridView;

public class FragmentMain extends Fragment {
    private MainActivity mainActivity;
	private GridView gridView;
	private SpeeddialAdapter adapter;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
	}
    
	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		mainActivity = (MainActivity) activity;
	}

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		View view = inflater.inflate(R.layout.fragment_main, null);
		gridView = (GridView) view.findViewById(R.id.gridview);
		adapter = new SpeeddialAdapter(getActivity());
		gridView.setAdapter(adapter);
		gridView.setOnItemClickListener(listener);
		return view;
	}
       
	private AdapterView.OnItemClickListener listener = new AdapterView.OnItemClickListener() {

		@Override
		public void onItemClick(AdapterView<?> arg0, View arg1, int position,
				long arg3) {
			Intent i;
			switch (position) {
			case 0:
			    i = new Intent(getActivity(),ActivityMediReminder.class);
				mainActivity.startActivity(i);
				break;
			case 1:
				i = new Intent(getActivity(),ActivityDoctorNotice.class);
				mainActivity.startActivity(i);
				break;
			case 2:
				i = new Intent(getActivity(),ActivityVaccineNotice.class);
				mainActivity.startActivity(i);
				break;
			case 3:
				i = new Intent(getActivity(),ActivityFollowUpRecord.class);
				mainActivity.startActivity(i);
				break;
			case 5:
				i = new Intent(getActivity(),ActivityCallAssistant.class);
				mainActivity.startActivity(i);
				break;
			case 6:
				i = new Intent(getActivity(),ActivityBookDoctor.class);
				mainActivity.startActivity(i);
				break;
			case 7:
				i = new Intent(getActivity(),ActivityHealthKnowl.class);
				mainActivity.startActivity(i);
				break;
			case 8:
				i = new Intent(getActivity(),ActivityHealthTest.class);
				mainActivity.startActivity(i);
				break;
			case 9:
				i = new Intent(getActivity(),ActivityCommunityActivity.class);
				mainActivity.startActivity(i);
				break;
			case 10:
				i = new Intent(getActivity(),ActivityWeatherNotice.class);
				mainActivity.startActivity(i);
				break;
			case 11:
				i = new Intent(getActivity(),ActivityHealthTip.class);
				mainActivity.startActivity(i);
				break;
			default:
				break;
			}
		}
	};
}
